home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group03a.txt / 000044_icon-group-sender_Tue Mar 25 16:50:34 2003.msg < prev    next >
Internet Message Format  |  2003-12-22  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h2PNnPs18801
  4.     for icon-group-addresses; Tue, 25 Mar 2003 16:49:25 -0700 (MST)
  5. Message-Id: <200303252349.h2PNnPs18801@baskerville.CS.Arizona.EDU>
  6. X-Authentication-Warning: weaver.tuc.noao.edu: swampler set sender to swampler@noao.edu using -f
  7. Subject: Re: newbie question -- ressurected
  8. From: Steve Wampler <swampler@noao.edu>
  9. To: Quiet Voice <voice_of_reason@australia.edu>
  10. Cc: icon-group@cs.arizona.edu
  11. Date: 25 Mar 2003 13:37:47 -0700
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14.  
  15. On Tue, 2003-03-25 at 11:44, Quiet Voice wrote:
  16. > Greetings:
  17. > Several years ago, I made a brief foray into trying to teach myself
  18. > the ICON programming language and develop some text analysis software.
  19. > After several fits-n-starts, the project sort of died on the vine.
  20. > I'm back at it again. Now, I'm trying to dig thru past code, remind
  21. > myself of what it was supposed to do and how...and shake out the
  22. > kinks.
  23. > I ran a piece of code this morning and discovered that it results in
  24. > an infinite loop.....but I can't figure out why.
  25. > here is the code fragment:
  26. > while not((line := read(data)) == "") do every
  27. > write(lettercount[!line] +:= 1)
  28. > {Note, this is one continuous line in the actual code}
  29. > "data" is an input text file
  30. > >From some debugging I've done, it seems like it keep reading from the
  31. > file after it reaches the end...it just loops back to the begining of
  32. > the file and starts over again. But I don't figure out why.
  33. > What am I missing?
  34.  
  35. I don't think it's looping back.  What is happening is
  36. that when the read(data) fails, the 'not' is converting that failure
  37. back into success (that's your infinite loop).
  38.  
  39. Since the assignment to line is performed after the read but before
  40. invoking not, line is retaining its last value (i.e. last line of the
  41. file), so you're seeing the characters in that last line counted over
  42. and over again.
  43.  
  44. 'not' is a tricky beast and shouldn't be confused with the not
  45. boolean operators in other languages.  In particular, you have
  46. two different points of failure in you while test clause and want
  47. to do different things on each.  While 'not' might be appropriate
  48. for one of those (the X == "") part, it isn't appropriate for
  49. the other.
  50.  
  51. Why not just try:
  52.  
  53.    while line := read(data) do
  54.       every lettercount[!line] +:= 1
  55.  
  56. instead of the above loop? (Yes, it doesn't print out each count as
  57. you compute it, but that's probably left over from debugging
  58. anyway.)  Empty lines will produce no characters in the ! operation,
  59. so you don't have to test for them.
  60.  
  61. (You can shorten the above even more, but that's probably
  62. not particularly important...)
  63.  
  64. Hope that helps!
  65. -- 
  66. Steve Wampler <swampler@noao.edu>
  67. National Solar Observatory
  68.